#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
    int p1, p2, p3, i;
    char    *pro1 = "./subp1", *pro2 = "./subp2", *pro3 = "./subp3";
    /*指针pro1、pro2、pro3指向的三个字符串分别是三个子进程代码文件的路径名*/
    char *argv[2];
    argv[1] = NULL;
    printf( "Parent is running!\n" );
    while ( (p1 = fork() ) == -1 );
    /*父进程创建第一个子进程*/
    if ( p1 == 0 )
    /*子进程1的代码入口*/
    {
        argv[0] = pro1;
        execv( pro1, argv );
        /*生成子进程1的独立映象*/
    }
    else
    {
        /*父进程的断点1的入口*/
        while ( (p2 = fork() ) == -1 );
        /*父进程创建第二个子进程*/
        if ( p2 == 0 )
        /*子进程2的代码入口*/
        {
            argv[0] = pro2;
            execv( pro2, argv );
            /*生成子进程2的独立映象*/
        }
        else
        {
            /*父进程的断点2的入口*/
            while ( (p3 = fork() ) == -1 );
            if ( p3 == 0 )
            {
                argv[0] = pro3;
                execv( pro3, argv );
            }
            else
            {
                /*父进程的断点3的入口*/
                for ( i = 0; i < 999999; i++ );
                printf( "Parent is over.\n" );
            }
        }
        wait(NULL);
        return 0;
    }
}
